
//
//  GKLHelpCenterTableHeader.m
//  jinwan
//
//  Created by GKiOS on 2017/6/6.
//  Copyright © 2017年 wy. All rights reserved.
//

#import "GKLHelpCenterTableHeader.h"

@interface GKLHelpCenterTableHeader ()
@property(nonatomic, strong) UILabel   *titleLabel;
@property(nonatomic, strong) UIButton   *downArrow;
@end

@implementation GKLHelpCenterTableHeader
- (instancetype)initWithReuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithReuseIdentifier:reuseIdentifier];
    if (self) {
        self.contentView.backgroundColor = [UIColor whiteColor];
        [self.contentView addSubview:self.titleLabel];
        [self.contentView addSubview:self.downArrow];
        [self createConstraints];
        [self createGest];
    }
    return self;
}

- (void)createConstraints
{
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView).offset(12);
        make.centerY.equalTo(self.contentView);
    }];
    
    [self.downArrow mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.contentView);
        make.right.equalTo(self.contentView).offset(-12);
    }];
}

- (void)createGest
{
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)];
    [self.contentView addGestureRecognizer:tap];
}

#pragma mark - action

- (void)tapAction:(UITapGestureRecognizer *)sender
{
    if (self.callBack) {
        self.callBack();
    }
}

#pragma mark - setter

- (void)setModel:(GKLHelpCenterModel *)model
{
    _model = model;
    self.titleLabel.text = _model.title;
    self.downArrow.selected = _model.isOpen;
}

#pragma mark - getter

- (UILabel *)titleLabel
{
    if (_titleLabel == nil) {
        _titleLabel = [[UILabel alloc] init];
        _titleLabel.textColor = [UIColor custom_color:@"#333333"];
        _titleLabel.font = [UIFont systemFontOfSize:14];
    }
    return _titleLabel;
}

- (UIButton *)downArrow
{
    if (_downArrow == nil) {
        _downArrow = [UIButton buttonWithType:UIButtonTypeCustom];
        [_downArrow setImage:[UIImage imageNamed:@"arrow_bottom_gray"] forState:UIControlStateNormal];
        [_downArrow setImage:[UIImage imageNamed:@"arrow_top_gray"] forState:UIControlStateSelected];
        _downArrow.userInteractionEnabled = NO;
    }
    return _downArrow;
}

@end
